<html>
<head><meta charset="utf-8"><title>anyone tested mimalloc? · t-compiler/windows · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/242869-t-compiler/windows/index.html">t-compiler/windows</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/242869-t-compiler/windows/topic/anyone.20tested.20mimalloc.3F.html">anyone tested mimalloc?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="203142770"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242869-t-compiler/windows/topic/anyone%20tested%20mimalloc%3F/near/203142770" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/242869-t-compiler/windows/topic/anyone.20tested.20mimalloc.3F.html#203142770">(Jul 07 2020 at 18:45)</a>:</h4>
<p>according to <a href="http://lists.llvm.org/pipermail/llvm-dev/2020-July/143015.html">http://lists.llvm.org/pipermail/llvm-dev/2020-July/143015.html</a> someone found that mimalloc was a massive (19x) speedup for their workload. I was curious, has anyone tested mimalloc on rustc for Windows? (I forget if there were attempts when it first came out or not). If not this may be an easy win for performance on Windows. IIRC we use jemalloc on Linux/macOS (and only on x86-64!) and we don't use it on Windows</p>



<a name="203142845"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242869-t-compiler/windows/topic/anyone%20tested%20mimalloc%3F/near/203142845" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/242869-t-compiler/windows/topic/anyone.20tested.20mimalloc.3F.html#203142845">(Jul 07 2020 at 18:45)</a>:</h4>
<p>That thread indicates that multithreaded allocations behave poorly with the default system allocator, which is ThinLTO for us, so we possibly stand to gain a nontrivial amount for release builds by switching allocators.</p>



<a name="203145407"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242869-t-compiler/windows/topic/anyone%20tested%20mimalloc%3F/near/203145407" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/242869-t-compiler/windows/topic/anyone.20tested.20mimalloc.3F.html#203145407">(Jul 07 2020 at 19:02)</a>:</h4>
<p>I think we tried it for linux, but since we don't have perf.r-l.o on windows no one checked there</p>



<a name="203145602"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242869-t-compiler/windows/topic/anyone%20tested%20mimalloc%3F/near/203145602" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/242869-t-compiler/windows/topic/anyone.20tested.20mimalloc.3F.html#203145602">(Jul 07 2020 at 19:04)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/pulls?q=is%3Apr+mimalloc+is%3Aclosed">https://github.com/rust-lang/rust/pulls?q=is%3Apr+mimalloc+is%3Aclosed</a></p>



<a name="203147377"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242869-t-compiler/windows/topic/anyone%20tested%20mimalloc%3F/near/203147377" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/242869-t-compiler/windows/topic/anyone.20tested.20mimalloc.3F.html#203147377">(Jul 07 2020 at 19:16)</a>:</h4>
<p>yeah I suspect jemalloc vs mimalloc is a relatively close perf difference, but mimalloc vs system windows allocator is likely to be a lot bigger</p>



<a name="203147390"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242869-t-compiler/windows/topic/anyone%20tested%20mimalloc%3F/near/203147390" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/242869-t-compiler/windows/topic/anyone.20tested.20mimalloc.3F.html#203147390">(Jul 07 2020 at 19:16)</a>:</h4>
<p>this would have to be locally tested as well vs done through perf</p>



<a name="203269290"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242869-t-compiler/windows/topic/anyone%20tested%20mimalloc%3F/near/203269290" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/242869-t-compiler/windows/topic/anyone.20tested.20mimalloc.3F.html#203269290">(Jul 08 2020 at 13:50)</a>:</h4>
<p>We never actually got around to running perf tests with mimalloc though.</p>



<a name="203269908"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242869-t-compiler/windows/topic/anyone%20tested%20mimalloc%3F/near/203269908" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/242869-t-compiler/windows/topic/anyone.20tested.20mimalloc.3F.html#203269908">(Jul 08 2020 at 13:55)</a>:</h4>
<p>There were some initial tests that showed wall-time regressions, but it looks like that may have been incomplete replacement of jemalloc with mimalloc. It looks like the complete replacement ran into <a href="https://github.com/microsoft/mimalloc/issues/77">https://github.com/microsoft/mimalloc/issues/77</a>, though apparently that's been resolved somewhat since then. I imagine we could test again now.</p>



<a name="203316290"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242869-t-compiler/windows/topic/anyone%20tested%20mimalloc%3F/near/203316290" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mati865 <a href="https://rust-lang.github.io/zulip_archive/stream/242869-t-compiler/windows/topic/anyone.20tested.20mimalloc.3F.html#203316290">(Jul 08 2020 at 20:08)</a>:</h4>
<p>IIRC initial tests with the regression were using mimalloc with additional checks enabled (meant for debugging) aside of the other issues.</p>



<a name="203350648"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242869-t-compiler/windows/topic/anyone%20tested%20mimalloc%3F/near/203350648" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Peter Rabbit <a href="https://rust-lang.github.io/zulip_archive/stream/242869-t-compiler/windows/topic/anyone.20tested.20mimalloc.3F.html#203350648">(Jul 09 2020 at 04:49)</a>:</h4>
<p>Windows 10.0.19041 also has a new segment heap that we can opt into by setting a flag in the manifest (you know, that thing that Rust <em>still</em> refuses to provide first class support for). It's much faster than the default NT heap and avoids the code size penalty of statically linking a custom allocator.</p>



<a name="203362436"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242869-t-compiler/windows/topic/anyone%20tested%20mimalloc%3F/near/203362436" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mati865 <a href="https://rust-lang.github.io/zulip_archive/stream/242869-t-compiler/windows/topic/anyone.20tested.20mimalloc.3F.html#203362436">(Jul 09 2020 at 08:41)</a>:</h4>
<blockquote>
<p>you know, that thing that Rust still refuses to provide first class support for</p>
</blockquote>
<p>In windows-gnu world it's as simple as calling <code>ar</code> and <code>windres</code> with few arguments. Does msvc have something similar?</p>



<a name="203365790"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242869-t-compiler/windows/topic/anyone%20tested%20mimalloc%3F/near/203365790" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Peter Rabbit <a href="https://rust-lang.github.io/zulip_archive/stream/242869-t-compiler/windows/topic/anyone.20tested.20mimalloc.3F.html#203365790">(Jul 09 2020 at 09:23)</a>:</h4>
<p><span class="user-mention silent" data-user-id="119581">mati865</span> <a href="#narrow/stream/242869-t-compiler.2Fwindows/topic/anyone.20tested.20mimalloc.3F/near/203362436">said</a>:</p>
<blockquote>
<blockquote>
<p>you know, that thing that Rust still refuses to provide first class support for</p>
</blockquote>
<p>In windows-gnu world it's as simple as calling <code>ar</code> and <code>windres</code> with few arguments. Does msvc have something similar?</p>
</blockquote>
<p>Actually <code>pc-windows-msvc</code> has something even better which is the <code>/MANIFESTINPUT</code> linker argument that allows multiple dependencies to all specify input manifests which get merged together into a final manifest that is embedded in the binary. Granted we still don't have a stable way to programmatically specify linker arguments (except for <code>cdylib</code>s)...</p>
<p>Without <code>/MANIFESTINPUT</code> things get kinda gross as you can only embed a single manifest into a binary, however multiple dependencies may want to add things into your manifest and without <strong><em>first class</em></strong> support for that from Rust that just won't work. To support <code>pc-windows-gnu</code> properly Rust would have to handle the merging of manifests itself which means Rust/Cargo would have to expose a dedicated option to specify manifest input files.</p>
<p>The current method of compiling a resource file to embed a manifest, and then tricking rust into thinking that resource file is an import library so it passes it through to the linker untouched, only works when you have a single manifest and is not a robust solution.</p>



<a name="203371226"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242869-t-compiler/windows/topic/anyone%20tested%20mimalloc%3F/near/203371226" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mati865 <a href="https://rust-lang.github.io/zulip_archive/stream/242869-t-compiler/windows/topic/anyone.20tested.20mimalloc.3F.html#203371226">(Jul 09 2020 at 10:33)</a>:</h4>
<p>In the past LD was corrupting executables if multiple manifests were linked but at least some of those issues are fixed: <a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69880">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69880</a><br>
LLD's MinGW driver is a wrapper that calls <code>lld-link</code> with proper arguments so exposing <code>/MANIFESTINPUT</code> as <code>--manifestinput</code> or something similar should be trivial.</p>



<a name="207368313"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242869-t-compiler/windows/topic/anyone%20tested%20mimalloc%3F/near/207368313" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luqman Aden <a href="https://rust-lang.github.io/zulip_archive/stream/242869-t-compiler/windows/topic/anyone.20tested.20mimalloc.3F.html#207368313">(Aug 19 2020 at 04:08)</a>:</h4>
<p>I'd be glad to start writing an RFC for this but unsure how that'll go considering there are crates windres and embed-resource that you can use in <a href="http://build.rs">build.rs</a> today. The only downside is no direct support for multiple manifests but that's not exactly a normal usecase.</p>



<a name="207373737"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242869-t-compiler/windows/topic/anyone%20tested%20mimalloc%3F/near/207373737" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luqman Aden <a href="https://rust-lang.github.io/zulip_archive/stream/242869-t-compiler/windows/topic/anyone.20tested.20mimalloc.3F.html#207373737">(Aug 19 2020 at 06:16)</a>:</h4>
<p>Either way, here's a start: <a href="https://github.com/luqmana/rfcs/blob/windows-manifests/text/0000-windows-manifests.md">https://github.com/luqmana/rfcs/blob/windows-manifests/text/0000-windows-manifests.md</a> :)</p>



<a name="215194482"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242869-t-compiler/windows/topic/anyone%20tested%20mimalloc%3F/near/215194482" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/242869-t-compiler/windows/topic/anyone.20tested.20mimalloc.3F.html#215194482">(Oct 31 2020 at 14:37)</a>:</h4>
<p><span class="user-mention" data-user-id="125267">@Peter Rabbit</span> It seems like the new segment heap is slower, but uses less memory. Apparently that's what Chrome found too.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>